package com.qimu.saiyou.mq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.qimu.saiyou.config.DelayExchangeConfig.DEADLINE_DELAY_EXCHANGE;
import static com.qimu.saiyou.config.DelayExchangeConfig.DEADLINE_DELAY_ROUTING_KEY;

/**
 * @Author: FeiXiang
 * @Date: 2024/01/29 11:29:33
 * @Version: 1.0
 * @Description: 消息生成器
 */
@Component
public class DeadlineMessageProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     *
     * @param message   消息
     * @param delayTime 延迟时间
     */
    public void sendMessage(String message, Integer delayTime) {
        rabbitTemplate.convertAndSend(DEADLINE_DELAY_EXCHANGE, DEADLINE_DELAY_ROUTING_KEY, message, msg -> {
            msg.getMessageProperties().setDelay(delayTime);
            return msg;
        });
    }
}